package cn.gx.kevin.controller;
import java.io.File;
import java.util.*;

import cn.gx.kevin.common.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.gx.kevin.common.ui.AjaxResult;
import cn.gx.kevin.common.annotation.ApiDescript;
import cn.gx.kevin.common.annotation.ApiParams;
import cn.gx.kevin.common.annotation.ApiParamsDesc;
import cn.gx.kevin.common.annotation.ApiReturnDesc;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpServletRequest;
import cn.gx.kevin.controller.ResetfulBaseController;
import cn.gx.kevin.service.IBaseService;
import cn.gx.kevin.domain.BaseLog;
import cn.gx.kevin.service.IBaseLogService;

/**
*Generate by Kevin's CodeBuilder  2022-01-27 03:22
**/
@ApiDescript("") 
@Controller 
@RequestMapping(value="/baselog")
public class BaseLogController extends ResetfulBaseController<BaseLog, String> {

	IBaseLogService  baseLogService; 

	@Resource(name="baseLogService") 
	@Override 
	public void setService(IBaseService<BaseLog, String> service) {
		this.service = service;
		baseLogService = (IBaseLogService)service;
	}


	/****生成默认的CURD API，如不需要请删除，上传下载，xls导入导出请自行重写实现*****/

	@Override
	@ApiDescript("Get方式，负责页面请求,如:http://127.0.0.1/web/ctrl/page/[PageName]")
	@RequestMapping(value ="/page/{pageName}", method = RequestMethod.GET)
	public String page(@PathVariable("pageName") String pageName, HttpServletRequest request) throws Exception {
		if("index".equals(pageName)){
			Date now = new Date();
			try{
				String preDay = DateUtils.formatDateTime( DateUtils.computedDateByNow(now,-5,"d"),"yyyy-MM-dd 00:00:00");
				String nowDay = DateUtils.formatDateTime(now,"yyyy-MM-dd 23:59:59");
				request.setAttribute("preDay",preDay);
				request.setAttribute("nowDay",nowDay);
			}catch (Exception x){
			}
		}
		return super.page(pageName, request);
	}

	/***设置页面模块的子路径****/
	@Override
	public String setPageModelPath(HttpServletRequest request) {
		return "base" + File.separator + entityPath.toLowerCase();
	}

	/***设置datagrid的模块路径,默认base文件夹模块****/
	@Override
	public String setGridModelPath(HttpServletRequest request) {
		return "base" + File.separator;
	}



	@ApiReturnDesc("{ code: '0正确/1异常',message: '信息',data: '数据对象'}")
	@ApiParamsDesc("{idList:'id集合,[,]逗号分隔'}")
	@ApiParams("{'idList':'id1,id2'}")
	@ApiDescript("删除")
	@Override
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public @ResponseBody AjaxResult delete(HttpServletRequest request) throws Exception {
		return super.delete(request);
	}

	/***删除前约束检查，返回空则执行删除，否则返回对应的提示信息****/
	@Override
	protected String checkContraints(List<String> pks,HttpServletRequest request) throws Exception {
		return null;
	}

	@ApiReturnDesc("{ code: '0正确/1异常',message: '信息',data: '分页的数据对象'}")
	@ApiParamsDesc("{ page: '当前页',pageSize: '页大小',_col_sort_fieldName: 'desc/asc，_col_sort_为前缀标志，fieldName为需要排序的字段名'}")
	@ApiDescript("分页多条件可排序查询")
	@ApiParams("{'page':1,'pageSize':15,'_col_sort_fieldName':'asc'}")
	@Override
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public @ResponseBody AjaxResult list(HttpServletRequest request) throws Exception {
		return super.list(request);
	}

	/***分页多条件查询参数设置****/
	@Override
	public Map<String, Object> setListParams(HttpServletRequest request) {
		Map<String, Object> prMap = new HashMap<String, Object>();
		String userName =	request.getParameter("userName");
		if(StringUtils.isNotEmpty(userName)){
			prMap.put("userName",userName);
		}
		String start =	request.getParameter("start");
		if(StringUtils.isNotEmpty(start)){
			prMap.put("start",start);
		}
		String end =	request.getParameter("end");
		if(StringUtils.isNotEmpty(end)){
			prMap.put("end",end);
		}
		return prMap;
	}

}
